<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :before-close="closeDialog"
    title="支付"
    width="500px"
    center
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="100px"
      size="mini"
    >
      <el-form-item label="账号：" prop="userId">
        <el-input v-model="form.userId" style="width: 340px" disabled />
      </el-form-item>

      <el-form-item label="金额：" prop="amount">
        <el-input-number v-model="form.amount" style="width: 340px" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button size="small" @click="closeDialog">取 消</el-button>
        <el-button size="small" type="primary" @click="enterDialog"
          >确 定</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { getRecharge, gePay } from "@/api/modules/user";
export default {
  name: "adduser",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      form: {
        userId: "",
        amount: 0,
      },
      rules: {
        userId: [
          {
            required: true,
            message: "账户不能为空!",
            trigger: "blur",
          },
        ],
        amount: [
          {
            required: true,
            message: "密码不能为空!",
            trigger: "blur",
          },
        ],
      },
      loading: false,
    };
  },
  created() {
    this.form.userId = localStorage.getItem("userId");
  },
  methods: {
    handleSubmit() {
      console.log("handleSubmit!");
    },
    closeDialog() {
      this.$emit("closeDialog", false);
    },
    enterDialog() {
      this.loading = true;

      gePay(this.form).then((res) => {
        console.log(res);
        this.loading = false;
        if (res.code == 200) {
          this.$message({
            message: "支付成功",
            type: "success",
          });
          this.$emit("payed", true);
          this.$emit("closeDialog", false);
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
h1 {
  padding-top: 25px;
  padding-bottom: 25px;
}
</style>
